package cn.com.spic.demo.impl;

import cn.com.spic.demo.api.SpecialProjectService;
import cn.com.spic.demo.dao.SpecialProDAO;
import cn.com.spic.demo.dto.SpecialProjectDTO;
import cn.com.spic.demo.po.SpecialProjectPO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecialProjectServiceImpl implements SpecialProjectService {

    @Autowired
    private SpecialProDAO newSpecialProDAO;

    @Override
    public List<SpecialProjectDTO> getAllSpecialProList() {
        List<SpecialProjectPO> poList = newSpecialProDAO.getAllSpecialProList(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"});
        List<SpecialProjectDTO> dtoList = new ArrayList<>();
        for (SpecialProjectPO po : poList) {
            SpecialProjectDTO dto = new SpecialProjectDTO();
            BeanUtils.copyProperties(po, dto);
            dtoList.add(dto);
        }
        return dtoList;
    }

    @Override
    public SpecialProjectDTO getOneSpecialPro(String id) {
        List<SpecialProjectPO> poList = newSpecialProDAO.getOneSpecialPro(id);
        List<SpecialProjectDTO> dtoList = new ArrayList<>();
        for (SpecialProjectPO po : poList) {
            SpecialProjectDTO dto = new SpecialProjectDTO();
            BeanUtils.copyProperties(po, dto);
            dtoList.add(dto);
        }
        return dtoList.get(0);
    }

    @Override
    public List<SpecialProjectDTO> getSpecialByName(String askNineName) {
        List<SpecialProjectPO> poList = newSpecialProDAO.getSpecialByName(askNineName);
        List<SpecialProjectDTO> dtoList = new ArrayList<>();
        for (SpecialProjectPO po : poList) {
            SpecialProjectDTO dto = new SpecialProjectDTO();
            BeanUtils.copyProperties(po, dto);
            dtoList.add(dto);
        }
        return dtoList;
    }
}
